dynamic class classes.Map
{
    var TERRITORY_SIZE_min: Number = 17;
    var TERRITORY_SIZE_max: Number = 28;
    var BORDER_COLOR: Number = 4143636;
    var BORDER_ACTIVE_COLOR: Number = 16777215;
    var BORDER_OVER_COLOR: Number = 13421772;
    var BORDER_SIZE: Number = 2;
    var AV_UNITS_PER_TERRITORY: Number = 3;
    var COLOR_ARR = [11304249, 7041575, 4541257, 10439479, 5801101, 7419137, 8092812, 4866561];
    var CHOSEN_TERR_A;
    var CHOSEN_TERR_B;
    var GAME_CLASS;
    var HEX;
    var MAP_ARR;
    var ROOT_MC;
    var TERRITORIES_ARR;
    var TERR_A_NArr;
    var _territory;
    var cos30;
    var cos60;
    var counter;
    var rubbish_arr;
    var sin60;

    function Map(rmc, gc)
    {
        this.ROOT_MC = rmc;
        this.GAME_CLASS = gc;
        this.HEX = new classes.models.Hex();
        this.cos30 = Math.cos(this.deg2rad(30));
        this.cos60 = Math.cos(this.deg2rad(60));
        this.sin60 = Math.sin(this.deg2rad(60));
    }

    function createMap(players)
    {
        var __reg23 = 34;
        var __reg24 = 29;
        var __reg27 = 30;
        var __reg28 = 34;
        var __reg26 = this.random2(__reg28 - __reg27) + __reg27;
        if (this.rubbish_arr.length > 0) 
        {
            this.clearAll();
        }
        this.rubbish_arr = new Array();
        this.CHOSEN_TERR_A = this.CHOSEN_TERR_B = undefined;
        this.TERRITORIES_ARR = new Array();
        this.MAP_ARR = new Array();
        this.counter = 0;
        this.drawGrid(__reg23, __reg24);
        while (this.TERRITORIES_ARR.length < __reg26) 
        {
            var __reg10 = undefined;
            var __reg9 = undefined;
            if (this.TERRITORIES_ARR.length == 0) 
            {
                var __reg13 = Math.round((__reg23 - 1) / 2);
                var __reg12 = Math.round((__reg24 - 1) / 2);
                __reg10 = Math.round(0.25 * __reg13 + this.random2(0.5 * __reg13));
                __reg9 = Math.round(0.25 * __reg12 + this.random2(0.5 * __reg12));
            }
            else 
            {
                var __reg8 = false;
                while (!__reg8) 
                {
                    var __reg5 = this.random2(this.TERRITORIES_ARR.length - 1);
                    var __reg6 = this.TERRITORIES_ARR[__reg5].arr.length - 1;
                    while (__reg6 >= 0) 
                    {
                        var __reg3 = this.freeNeighboursArr2(this.TERRITORIES_ARR[__reg5].arr[__reg6]);
                        if (__reg3.length > 0) 
                        {
                            var __reg4 = this.random2(__reg3.length - 1);
                            __reg10 = __reg3[__reg4].x;
                            __reg9 = __reg3[__reg4].y;
                            __reg8 = true;
                        }
                        --__reg6;
                    }
                }
            }
            var __reg7 = this.newTerritory(__reg10, __reg9);
            if (__reg7.length > 0) 
            {
                var __reg11 = {status: 0, player: 0, border: undefined, army: 0, unitsMC: undefined, unitsNO: 0, arr: __reg7};
                __reg6 = 0;
                while (__reg6 < __reg7.length) 
                {
                    __reg7[__reg6]._territory = __reg11;
                    ++__reg6;
                }
                this.TERRITORIES_ARR.push(__reg11);
            }
        }
        var __reg25 = _root.ARMY;
        var __reg15 = new Array();
        __reg6 = 0;
        while (__reg6 < players) 
        {
            __reg15.push((__reg6 + __reg25 - 1) % 3 + 1);
            ++__reg6;
        }
        __reg6 = 0;
        while (__reg6 < this.TERRITORIES_ARR.length) 
        {
            this.makeBorder(this.TERRITORIES_ARR[__reg6], this.HEX.__get__HEIGHT() / 2);
            this.markTerritory(this.TERRITORIES_ARR[__reg6], players - __reg6 % players, 0);
            this.TERRITORIES_ARR[__reg6].army = __reg15[this.TERRITORIES_ARR[__reg6].player - 1];
            ++__reg6;
        }
        this.randomUnits(players);
    }

    function startInterface()
    {
        this.selectA();
    }

    function markTerritory(terrObj, pl, stat)
    {
        var __reg2 = 0;
        while (__reg2 < terrObj.arr.length) 
        {
            terrObj.arr[__reg2]._visible = true;
            terrObj.arr[__reg2].gotoAndStop(pl);
            ++__reg2;
        }
        this.colorMC(terrObj.border, this.BORDER_COLOR);
        terrObj.status = stat;
        terrObj.player = pl;
    }

    function drawGrid(w, h)
    {
        var __reg11 = this.HEX.__get__WIDTH();
        var __reg7 = 0;
        while (__reg7 < h) 
        {
            var __reg8 = new Array();
            var __reg6 = 0;
            while (__reg6 < w) 
            {
                var __reg5 = this.ROOT_MC.attachMovie("HEX", "hex_" + __reg6 + "x" + __reg7, this.counter++);
                __reg5._x = __reg6 * this.HEX.__get__WIDTH() + __reg7 % 2 * (this.HEX.__get__WIDTH() / 2);
                __reg5._y = __reg7 * (this.HEX.__get__HEIGHT() / 2) * 1.5;
                __reg8.push(__reg5);
                __reg5.x = __reg6;
                __reg5.y = __reg7;
                __reg5._inTerritory = false;
                __reg5._onBorder = false;
                __reg5._visible = false;
                this.rubbish_arr.push(__reg5);
                ++__reg6;
            }
            this.MAP_ARR.push(__reg8);
            ++__reg7;
        }
        var __reg3 = 0;
        for (;;) 
        {
            if (__reg3 >= h) 
            {
                return;
            }
            var __reg2 = 0;
            while (__reg2 < w) 
            {
                var __reg4 = this.MAP_ARR[__reg3][__reg2];
                __reg4.L = this.MAP_ARR[__reg3][__reg2 - 1];
                __reg4.R = this.MAP_ARR[__reg3][__reg2 + 1];
                if (__reg3 % 2 == 0) 
                {
                    __reg4.TL = this.MAP_ARR[__reg3 - 1][__reg2 - 1];
                    __reg4.TR = this.MAP_ARR[__reg3 - 1][__reg2];
                    __reg4.BL = this.MAP_ARR[__reg3 + 1][__reg2 - 1];
                    __reg4.BR = this.MAP_ARR[__reg3 + 1][__reg2];
                }
                else 
                {
                    __reg4.TL = this.MAP_ARR[__reg3 - 1][__reg2];
                    __reg4.TR = this.MAP_ARR[__reg3 - 1][__reg2 + 1];
                    __reg4.BL = this.MAP_ARR[__reg3 + 1][__reg2];
                    __reg4.BR = this.MAP_ARR[__reg3 + 1][__reg2 + 1];
                }
                ++__reg2;
            }
            ++__reg3;
        }
    }

    function newTerritory(x, y)
    {
        var __reg2 = new Array(this.MAP_ARR[y][x]);
        this.MAP_ARR[y][x]._inTerritory = true;
        var __reg8 = this.random2(Math.round(this.TERRITORY_SIZE_max - this.TERRITORY_SIZE_min)) + this.TERRITORY_SIZE_min;
        var __reg7 = false;
        while (__reg2.length < __reg8 && !__reg7) 
        {
            var __reg6 = 0;
            __reg2 = this.shuffledArray(__reg2);
            var __reg3 = 0;
            while (__reg3 < __reg2.length) 
            {
                var __reg4 = this.freeNeighboursArr2(__reg2[__reg3]);
                if (__reg4.length > 0) 
                {
                    var __reg5 = __reg4[this.random2(__reg4.length - 1)];
                    __reg2.push(__reg5);
                    __reg5._inTerritory = true;
                    __reg3 = __reg2.length + 10;
                }
                else 
                {
                    ++__reg6;
                }
                ++__reg3;
            }
            if (__reg6 >= __reg2.length) 
            {
                __reg7 = true;
            }
        }
        if (__reg7) 
        {
            if (__reg2.length >= this.TERRITORY_SIZE_min) 
            {
                return __reg2;
            }
            else 
            {
                this.burnTerritory(__reg2);
                return new Array();
            }
        }
        return __reg2;
    }

    function neighbourTerritoriesNo(terrArr)
    {
        var __reg6 = new Array();
        var __reg7 = 0;
        while (__reg7 < terrArr.length) 
        {
            var __reg5 = terrArr[__reg7];
            var __reg3 = [__reg5.TL, __reg5.L, __reg5.TR, __reg5.BR, __reg5.R, __reg5.BL];
            var __reg1 = 0;
            while (__reg1 < __reg3.length) 
            {
                if (__reg3[__reg1]._territory != __reg5._territory && __reg3[__reg1]._territory != undefined) 
                {
                    var __reg4 = false;
                    var __reg2 = 0;
                    while (__reg2 < __reg6.length && !__reg4) 
                    {
                        if (__reg6[__reg2] == __reg3[__reg1]._territory) 
                        {
                            __reg4 = true;
                        }
                        ++__reg2;
                    }
                    if (!__reg4) 
                    {
                        __reg6.push(__reg3[__reg1]._territory);
                    }
                }
                ++__reg1;
            }
            ++__reg7;
        }
        return __reg6.length;
    }

    function freeNeighboursArr(mc)
    {
        var __reg3 = new Array();
        var __reg2 = [mc.TL, mc.L, mc.TR, mc.BR, mc.R, mc.BL];
        var __reg1 = 0;
        while (__reg1 < __reg2.length) 
        {
            if (__reg2[__reg1] != undefined && __reg2[__reg1]._inTerritory == false) 
            {
                __reg3.push(__reg2[__reg1]);
            }
            ++__reg1;
        }
        return __reg3;
    }

    function freeNeighboursArr2(mc)
    {
        var __reg4 = new Array();
        var __reg2 = [mc.TL, mc.L, mc.TR, mc.BR, mc.R, mc.BL, mc.L, mc.R, mc.L, mc.R];
        var __reg1 = 0;
        while (__reg1 < __reg2.length) 
        {
            if (__reg2[__reg1] != undefined && __reg2[__reg1]._inTerritory == false) 
            {
                __reg4.push(__reg2[__reg1]);
            }
            ++__reg1;
        }
        return __reg4;
    }

    function burnTerritory(terrArr)
    {
        var __reg1 = 0;
        for (;;) 
        {
            if (__reg1 >= terrArr.length) 
            {
                return;
            }
            terrArr[__reg1]._inTerritory = true;
            ++__reg1;
        }
    }

    function makeBorder(terrObj, r)
    {
        var __reg7 = this.BORDER_SIZE;
        var __reg6 = this.BORDER_COLOR;
        var __reg11 = new Array();
        var __reg10 = 0;
        while (__reg10 < terrObj.arr.length) 
        {
            var __reg8 = terrObj.arr[__reg10];
            var __reg9 = [__reg8.TL, __reg8.L, __reg8.TR, __reg8.BR, __reg8.R, __reg8.BL];
            var __reg5 = 0;
            while (__reg5 < __reg9.length) 
            {
                if (__reg9[__reg5]._territory != terrObj && !__reg8._onBorder) 
                {
                    __reg8._onBorder = true;
                    __reg11.push(__reg8);
                }
                ++__reg5;
            }
            ++__reg10;
        }
        var __reg2 = this.ROOT_MC.createEmptyMovieClip("border" + this.counter, this.counter++);
        __reg2._x = __reg11[0]._x;
        __reg2._y = __reg11[0]._y;
        terrObj.border = __reg2;
        this.rubbish_arr.push(__reg2);
        __reg10 = 0;
        for (;;) 
        {
            if (__reg10 >= __reg11.length) 
            {
                return;
            }
            __reg8 = __reg11[__reg10];
            var __reg4 = __reg8._x - __reg2._x;
            var __reg3 = __reg8._y - __reg2._y;
            __reg9 = [__reg8.TL, __reg8.L, __reg8.TR, __reg8.BR, __reg8.R, __reg8.BL];
            __reg5 = 0;
            while (__reg5 < __reg9.length) 
            {
                if (__reg9[__reg5]._territory != __reg8._territory || __reg9[__reg5] == undefined) 
                {
                    if ((__reg0 = __reg5) === 5) 
                    {
                        __reg2.lineStyle(__reg7, __reg6, 100);
                        __reg2.moveTo(__reg4 + this.HEX.__get__BL().x, __reg3 + this.HEX.__get__BL().y);
                        __reg2.lineTo(__reg4 + this.HEX.__get__B().x, __reg3 + this.HEX.__get__B().y);
                    }
                    else if (__reg0 === 1) 
                    {
                        __reg2.lineStyle(__reg7, __reg6, 100);
                        __reg2.moveTo(__reg4 + this.HEX.__get__BL().x, __reg3 + this.HEX.__get__BL().y);
                        __reg2.lineTo(__reg4 + this.HEX.__get__TL().x, __reg3 + this.HEX.__get__TL().y);
                    }
                    else if (__reg0 === 3) 
                    {
                        __reg2.lineStyle(__reg7, __reg6, 100);
                        __reg2.moveTo(__reg4 + this.HEX.__get__BR().x, __reg3 + this.HEX.__get__BR().y);
                        __reg2.lineTo(__reg4 + this.HEX.__get__B().x, __reg3 + this.HEX.__get__B().y);
                    }
                    else if (__reg0 === 2) 
                    {
                        __reg2.lineStyle(__reg7, __reg6, 100);
                        __reg2.moveTo(__reg4 + this.HEX.__get__TR().x, __reg3 + this.HEX.__get__TR().y);
                        __reg2.lineTo(__reg4 + this.HEX.__get__T().x, __reg3 + this.HEX.__get__T().y);
                    }
                    else if (__reg0 === 4) 
                    {
                        __reg2.lineStyle(__reg7, __reg6, 100);
                        __reg2.moveTo(__reg4 + this.HEX.__get__TR().x, __reg3 + this.HEX.__get__TR().y);
                        __reg2.lineTo(__reg4 + this.HEX.__get__BR().x, __reg3 + this.HEX.__get__BR().y);
                    }
                    else if (__reg0 === 0) 
                    {
                        __reg2.lineStyle(__reg7, __reg6, 100);
                        __reg2.moveTo(__reg4 + this.HEX.__get__TL().x, __reg3 + this.HEX.__get__TL().y);
                        __reg2.lineTo(__reg4 + this.HEX.__get__T().x, __reg3 + this.HEX.__get__T().y);
                    }
                }
                ++__reg5;
            }
            ++__reg10;
        }
    }

    function randomUnits(players)
    {
        var __reg12 = Math.round(this.AV_UNITS_PER_TERRITORY * this.TERRITORIES_ARR.length);
        var __reg9 = new Array();
        var __reg10 = new Array();
        var __reg5 = 0;
        while (__reg5 < players) 
        {
            __reg9.push(Math.floor(__reg12 / players));
            ++__reg5;
        }
        __reg5 = 0;
        while (__reg5 < __reg12 - Math.floor(__reg12 / players) * players) 
        {
            __reg9[__reg9.length - 1 - __reg5] = __reg9[__reg9.length - 1 - __reg5] + 1;
            ++__reg5;
        }
        var __reg15 = Math.floor(this.TERRITORIES_ARR.length / players);
        var __reg14 = this.TERRITORIES_ARR.length - players * Math.floor(this.TERRITORIES_ARR.length / players);
        __reg5 = 0;
        while (__reg5 < players) 
        {
            __reg10.push(__reg15);
            ++__reg5;
        }
        __reg5 = 0;
        while (__reg5 < __reg14) 
        {
            __reg10[__reg10.length - 1 - __reg5] = __reg10[__reg10.length - 1 - __reg5] + 1;
            ++__reg5;
        }
        var __reg13 = new Array();
        var __reg11 = new Array();
        __reg5 = 0;
        while (__reg5 < players) 
        {
            var __reg4 = __reg9[__reg5];
            var __reg7 = __reg10[__reg5];
            var __reg8 = new Array();
            var __reg3 = 0;
            while (__reg3 < __reg7) 
            {
                var __reg2 = 0;
                while (__reg2 > 8 || __reg2 < 1) 
                {
                    __reg2 = this.random2(Math.floor(__reg4 / 2) - 1) + 1;
                }
                if (__reg3 == __reg7 - 1) 
                {
                    __reg2 = __reg4;
                    if (__reg2 < 1) 
                    {
                        __reg2 = 1;
                    }
                }
                __reg8.push(__reg2);
                __reg4 = __reg4 - __reg2;
                ++__reg3;
            }
            __reg11.push(0);
            __reg13.push(__reg8);
            ++__reg5;
        }
        __reg5 = 0;
        for (;;) 
        {
            if (__reg5 >= this.TERRITORIES_ARR.length) 
            {
                return;
            }
            this.TERRITORIES_ARR[__reg5].unitsNO = __reg13[this.TERRITORIES_ARR[__reg5].player - 1][__reg11[this.TERRITORIES_ARR[__reg5].player - 1]];
            ++__reg11[this.TERRITORIES_ARR[__reg5].player - 1];
            ++__reg5;
        }
    }

    function territoryA(terr)
    {
        this.CHOSEN_TERR_A = terr;
        this.CHOSEN_TERR_B = undefined;
        this.colorMC(this.CHOSEN_TERR_A.border, this.BORDER_ACTIVE_COLOR);
        this.territoryMaxDepth(this.CHOSEN_TERR_A);
    }

    function territoryB(terr)
    {
        this.CHOSEN_TERR_B = terr;
        this.colorMC(this.CHOSEN_TERR_B.border, this.BORDER_ACTIVE_COLOR);
        var __reg2 = 0;
        for (;;) 
        {
            if (__reg2 >= this.TERRITORIES_ARR.length) 
            {
                return;
            }
            if (this.TERRITORIES_ARR[__reg2].border.getDepth() == this.CHOSEN_TERR_A.border.getDepth() - 1) 
            {
                this.CHOSEN_TERR_B.border.swapDepths(this.TERRITORIES_ARR[__reg2].border);
                __reg2 = this.TERRITORIES_ARR.length;
            }
            ++__reg2;
        }
    }

    function territoryMaxDepth(terrObj)
    {
        var __reg6 = this.TERRITORIES_ARR[0].border.getDepth();
        var __reg2 = new Array();
        var __reg5 = 0;
        while (__reg5 < this.TERRITORIES_ARR.length) 
        {
            if (this.TERRITORIES_ARR[__reg5].border.getDepth() < __reg6) 
            {
                __reg6 = this.TERRITORIES_ARR[__reg5].border.getDepth();
            }
            __reg2.push(this.TERRITORIES_ARR[__reg5].border);
            this.TERRITORIES_ARR[__reg5].border.swapDepths(__reg6 + 10 + this.TERRITORIES_ARR.length + __reg5);
            ++__reg5;
        }
        __reg5 = 0;
        while (__reg5 < __reg2.length) 
        {
            var __reg3 = __reg2.length - 1;
            while (__reg3 > __reg5) 
            {
                if (__reg2[__reg3 - 1].getDepth() > __reg2[__reg3].getDepth()) 
                {
                    var __reg4 = __reg2[__reg3];
                    __reg2[__reg3] = __reg2[__reg3 - 1];
                    __reg2[__reg3 - 1] = __reg4;
                }
                --__reg3;
            }
            ++__reg5;
        }
        __reg5 = 0;
        while (__reg5 < __reg2.length) 
        {
            if (__reg2[__reg5] == terrObj.border) 
            {
                __reg2.splice(__reg5, 1);
            }
            ++__reg5;
        }
        __reg2.push(terrObj.border);
        __reg5 = 0;
        for (;;) 
        {
            if (__reg5 >= __reg2.length) 
            {
                return;
            }
            __reg2[__reg5].swapDepths(__reg6 + __reg5);
            ++__reg5;
        }
    }

    function resetTerritory(terr)
    {
        if (this.CHOSEN_TERR_B == terr) 
        {
            this.CHOSEN_TERR_B = undefined;
        }
        if (this.CHOSEN_TERR_A == terr) 
        {
            this.CHOSEN_TERR_A = undefined;
        }
        this.markTerritory(terr, terr.player, 0);
    }

    function unMarkIfMarked()
    {
        this.colorMC(this.CHOSEN_TERR_A.border, this.BORDER_COLOR);
        this.deselectAll();
    }

    function selectA()
    {
        if (this.GAME_CLASS.isGameFinished()) 
        {
            return;
        }
        var root = this;
        var __reg4 = 0;
        for (;;) 
        {
            if (__reg4 >= this.TERRITORIES_ARR.length) 
            {
                return;
            }
            var __reg6 = false;
            var __reg7 = this.neighboursAreasArr(this.TERRITORIES_ARR[__reg4].arr);
            var __reg5 = 0;
            while (__reg5 < __reg7.length && !__reg6) 
            {
                if (__reg7[__reg5].player != this.TERRITORIES_ARR[__reg4].player) 
                {
                    __reg6 = true;
                }
                ++__reg5;
            }
            if (__reg6) 
            {
                __reg5 = 0;
                while (__reg5 < this.TERRITORIES_ARR[__reg4].arr.length) 
                {
                    var __reg3 = this.TERRITORIES_ARR[__reg4].arr[__reg5];
                    if (__reg3._territory.player == 1 && __reg3._territory.unitsNO > 1) 
                    {
                        __reg3.onRelease = function ()
                        {
                            _global.SOUNDS.playSound("Click- głośniejszy.wav");
                            if (this._territory == root.CHOSEN_TERR_A) 
                            {
                                root.colorMC(root.CHOSEN_TERR_A.border, root.BORDER_COLOR);
                                root.lightOffTerritory(root.CHOSEN_TERR_A);
                                root.deselectB();
                                root.CHOSEN_TERR_A = undefined;
                                return;
                            }
                            root.colorMC(root.CHOSEN_TERR_A.border, root.BORDER_COLOR);
                            root.lightOffTerritory(root.CHOSEN_TERR_A);
                            root.deselectB();
                            root.territoryA(this._territory);
                            root.lightOffTerritory(this._territory);
                            root.selectB();
                        }
                        ;
                        __reg3.onRollOver = function ()
                        {
                            if (this._territory != root.CHOSEN_TERR_A) 
                            {
                                root.lightOnTerritory(this._territory);
                            }
                        }
                        ;
                        __reg3.onRollOut = __reg3.onReleaseOutside = function ()
                        {
                            if (this._territory != root.CHOSEN_TERR_A) 
                            {
                                root.lightOffTerritory(this._territory);
                            }
                        }
                        ;
                    }
                    ++__reg5;
                }
            }
            ++__reg4;
        }
    }

    function selectB()
    {
        this.findAneighbours();
        var root = this;
        var __reg4 = 0;
        for (;;) 
        {
            if (__reg4 >= this.TERR_A_NArr.length) 
            {
                return;
            }
            if (this.TERR_A_NArr[__reg4].player != 1) 
            {
                var __reg3 = 0;
                while (__reg3 < this.TERR_A_NArr[__reg4].arr.length) 
                {
                    var __reg5 = this.TERR_A_NArr[__reg4].arr[__reg3];
                    __reg5.onRelease = function ()
                    {
                        _global.SOUNDS.playSound("Click- głośniejszy.wav");
                        root.territoryB(this._territory);
                        root.fightAB();
                        root.deselectAll();
                    }
                    ;
                    ++__reg3;
                }
            }
            ++__reg4;
        }
    }

    function deselectB()
    {
        this.findAneighbours();
        var __reg5 = this;
        var __reg3 = 0;
        for (;;) 
        {
            if (__reg3 >= this.TERR_A_NArr.length) 
            {
                return;
            }
            if (this.TERR_A_NArr[__reg3].player != 1) 
            {
                var __reg2 = 0;
                while (__reg2 < this.TERR_A_NArr[__reg3].arr.length) 
                {
                    var __reg4 = this.TERR_A_NArr[__reg3].arr[__reg2];
                    delete __reg4.onRelease;
                    ++__reg2;
                }
            }
            ++__reg3;
        }
    }

    function deselectA()
    {
        var __reg5 = this;
        var __reg4 = 0;
        for (;;) 
        {
            if (__reg4 >= this.TERR_A_NArr.length) 
            {
                return;
            }
            if (this.TERR_A_NArr[__reg4].player == 1) 
            {
                var __reg3 = 0;
                while (__reg3 < this.TERR_A_NArr[__reg4].arr.length) 
                {
                    var __reg2 = this.TERR_A_NArr[__reg4].arr[__reg3];
                    delete __reg2.onRollOut;
                    delete (__reg2.onReleaseOutside);
                    delete __reg2.onRollOver;
                    delete (__reg2.onRelease);
                    ++__reg3;
                }
            }
            ++__reg4;
        }
    }

    function deselectAll()
    {
        var __reg3 = 0;
        for (;;) 
        {
            if (__reg3 >= this.TERRITORIES_ARR.length) 
            {
                return;
            }
            var __reg2 = 0;
            while (__reg2 < this.TERRITORIES_ARR[__reg3].arr.length) 
            {
                delete this.TERRITORIES_ARR[__reg3].arr[__reg2].onRollOver;
                delete this.TERRITORIES_ARR[__reg3].arr[__reg2].onRollOut;
                delete this.TERRITORIES_ARR[__reg3].arr[__reg2].onReleaseOutside;
                delete this.TERRITORIES_ARR[__reg3].arr[__reg2].onRelease;
                ++__reg2;
            }
            ++__reg3;
        }
    }

    function findAneighbours()
    {
        this.TERR_A_NArr = new Array();
        var __reg8 = this.CHOSEN_TERR_A.arr;
        var __reg7 = 0;
        for (;;) 
        {
            if (__reg7 >= __reg8.length) 
            {
                return;
            }
            var __reg6 = __reg8[__reg7];
            var __reg4 = [__reg6.TL, __reg6.L, __reg6.TR, __reg6.BR, __reg6.R, __reg6.BL];
            var __reg2 = 0;
            while (__reg2 < __reg4.length) 
            {
                if (__reg4[__reg2]._territory != __reg6._territory && __reg4[__reg2]._territory != undefined) 
                {
                    var __reg5 = false;
                    var __reg3 = 0;
                    while (__reg3 < this.TERR_A_NArr.length && !__reg5) 
                    {
                        if (this.TERR_A_NArr[__reg3] == __reg4[__reg2]._territory) 
                        {
                            __reg5 = true;
                        }
                        ++__reg3;
                    }
                    if (!__reg5) 
                    {
                        this.TERR_A_NArr.push(__reg4[__reg2]._territory);
                    }
                }
                ++__reg2;
            }
            ++__reg7;
        }
    }

    function neighboursAreasArr(terrArr)
    {
        var __reg6 = new Array();
        var __reg7 = 0;
        while (__reg7 < terrArr.length) 
        {
            var __reg5 = terrArr[__reg7];
            var __reg3 = [__reg5.TL, __reg5.L, __reg5.TR, __reg5.BR, __reg5.R, __reg5.BL];
            var __reg1 = 0;
            while (__reg1 < __reg3.length) 
            {
                if (__reg3[__reg1]._territory != __reg5._territory && __reg3[__reg1]._territory != undefined) 
                {
                    var __reg4 = false;
                    var __reg2 = 0;
                    while (__reg2 < __reg6.length && !__reg4) 
                    {
                        if (__reg6[__reg2] == __reg3[__reg1]._territory) 
                        {
                            __reg4 = true;
                        }
                        ++__reg2;
                    }
                    if (!__reg4) 
                    {
                        __reg6.push(__reg3[__reg1]._territory);
                    }
                }
                ++__reg1;
            }
            ++__reg7;
        }
        return __reg6;
    }

    function lightOnTerritory(terrObj)
    {
        var __reg1 = 0;
        for (;;) 
        {
            if (__reg1 >= terrObj.arr.length) 
            {
                return;
            }
            terrObj.arr[__reg1]._alpha = 70;
            ++__reg1;
        }
    }

    function lightOffTerritory(terrObj)
    {
        var __reg1 = 0;
        for (;;) 
        {
            if (__reg1 >= terrObj.arr.length) 
            {
                return;
            }
            terrObj.arr[__reg1]._alpha = 100;
            ++__reg1;
        }
    }

    function fightAB()
    {
        this.GAME_CLASS.FIGHTBOX.resetWinner();
        this.GAME_CLASS.FIGHTBOX.fight(this.CHOSEN_TERR_A, this.CHOSEN_TERR_B);
    }

    function winnerFound()
    {
        if (this.GAME_CLASS.FIGHTBOX.WINNER == this.CHOSEN_TERR_A) 
        {
            this.winA();
            if (this.GAME_CLASS.PLAYER_MOVE == 1 && !this.GAME_CLASS.isGameFinished()) 
            {
                _global.setTimeout(mx.utils.Delegate.create(this.GAME_CLASS, this.GAME_CLASS.showBiggestArea), 300);
            }
        }
        if (this.GAME_CLASS.FIGHTBOX.WINNER == this.CHOSEN_TERR_B) 
        {
            this.winB();
        }
        var __reg4 = new Array();
        var __reg3 = 1;
        while (__reg3 <= this.GAME_CLASS.PLAYERS_NO) 
        {
            __reg4.push(this.GAME_CLASS.unitsToAdd(__reg3));
            ++__reg3;
        }
        this.GAME_CLASS.UNITS_LIST.refreshList(__reg4, this.TERRITORIES_ARR);
    }

    function winA()
    {
        this.markTerritory(this.CHOSEN_TERR_B, this.CHOSEN_TERR_A.player, 0);
        this.CHOSEN_TERR_B.unitsNO = this.CHOSEN_TERR_A.unitsNO - 1;
        this.CHOSEN_TERR_A.unitsNO = 1;
        this.CHOSEN_TERR_B.army = this.CHOSEN_TERR_A.army;
        this.CHOSEN_TERR_A.unitsMC.setUnit(this.CHOSEN_TERR_A.army, this.CHOSEN_TERR_A.unitsNO, this.CHOSEN_TERR_A.player);
        this.CHOSEN_TERR_B.unitsMC.setUnit(this.CHOSEN_TERR_A.army, this.CHOSEN_TERR_B.unitsNO, this.CHOSEN_TERR_B.player);
        this.resetTerritory(this.CHOSEN_TERR_A);
        this.resetTerritory(this.CHOSEN_TERR_B);
        this.deselectAll();
    }

    function winB()
    {
        this.CHOSEN_TERR_A.unitsNO = 1;
        this.CHOSEN_TERR_A.unitsMC.setUnit(this.CHOSEN_TERR_A.army, this.CHOSEN_TERR_A.unitsNO, this.CHOSEN_TERR_A.player);
        this.resetTerritory(this.CHOSEN_TERR_A);
        this.resetTerritory(this.CHOSEN_TERR_B);
        this.deselectAll();
    }

    function colorMC(mc, cl)
    {
        var __reg1 = new Color(mc);
        __reg1.setRGB(cl);
    }

    function rad2deg(rad)
    {
        return rad * 180 / 3.14159265359;
    }

    function deg2rad(deg)
    {
        return deg * 3.14159265359 / 180;
    }

    function random2(z)
    {
        return Math.round(Math.random() * z);
    }

    function shuffledArray(arr)
    {
        var __reg5 = 0;
        while (__reg5 < 30) 
        {
            var __reg4 = this.random2(arr.length - 1);
            var __reg3 = this.random2(arr.length - 1);
            var __reg6 = arr[__reg4];
            arr[__reg4] = arr[__reg3];
            arr[__reg3] = __reg6;
            ++__reg5;
        }
        return arr;
    }

    function clearAll()
    {
        var __reg2 = 0;
        for (;;) 
        {
            if (__reg2 >= this.rubbish_arr.length) 
            {
                return;
            }
            this.rubbish_arr[__reg2].removeMovieClip();
            ++__reg2;
        }
    }

}
